package KK.War
{
	import KK.Data.GameData;
	import KK.EMVC.Control.Control;
	import KK.Event.GameSystemEvent;
	import KK.GameBase.IMessageQueue;
	import KK.GameBase.MSGEvent;
	import KK.Role.Army;
	import KK.net.ResourceManager;
	
	import Protocol.SArmyInfo;
	import Protocol.SBattleInfo;
	import Protocol.SBattleResult;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.Graphics;
	import flash.display.Sprite;
	
	public class MainHanlder extends Control
	{
		private var _ArmyList: Vector.<Army>;
		private var _armyInfoList: Vector.<SArmyInfo>;
		private var _cuteQueue: Vector.<SBattleInfo>;
		
	
		private var scene:DisplayObjectContainer;

		public function MainHanlder(scene:Battle)
		{
			//TODO: implement function
			this.scene=scene;
			super();
			init();
		}
		
		
		/**
		 * 初始化  
		 * 
		 */
		private function init():void{
			
		} 
		
		/**
		 * 绑定事件 
		 * @param _event
		 * @return 
		 * 
		 */
		override public function BindEvent(_event:IMessageQueue):Boolean{
			super.BindEvent(_event);
			initEvent();
			return true;
		}
		
		
		
		
		/**
		 * 初始化军队形象
		 */
		protected function InitArmyImage(): void
		{
			
			
			_ArmyList=new Vector.<Army>(_armyInfoList.length,true);
			var i:int=0;
			const len:int=_ArmyList.length;
			while(i<len){
				_ArmyList[i]=new Army();
				_ArmyList[i].SetInfo(_armyInfoList[i]);
				scene.addChild(_ArmyList[i].GetMC());
				i++;
			}
		}
		
		/**
		 * 初始化地图  
		 * 
		 */
		protected function InitMap(): void
		{
			
		}
		
		/**
		 * 开始运行
		 */
		public function Run(): void
		{
		}
		
		/**
		 * 设置战斗数据
		 * 
		 * @param data    data
		 */
		public function SetBattleData(data:SBattleResult): void
		{
			_armyInfoList=data.battleHead.armys;
			
			InitArmyImage();
			GameData.Word.addChild(scene);
		}
		
		
		/**
		 * 停止运行
		 */
		public function Stop(): void
		{
		}
		
		/**
		 * 初始化事件  
		 * 
		 */
		private function initEvent():void{
			AttentionMessage(GameSystemEvent.START_BATTLE,onBattle);
			
		}
		
		
		/**
		 *  
		 * @param event
		 * 
		 */
		private function onBattle(event:MSGEvent):void{
			SetBattleData(GameData.BattleData);
		}
		 
	}
}